﻿/*-------------------------------------------------------------------------
* 命名空间: SiliconSelect.ViewModels/BoxSettingsViewModel
* 类       名: BoxSettingsViewModel
* 功      能:  绑定料盒和设定值ViewModel
* 时      间:  2023/9/22 16:14:20
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using SiliconSelect.Base;
using SiliconSelect.BLL;
using SiliconSelect.DAL.DataEntity;
using SiliconSelect.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SiliconSelect.ViewModels
{
    public class BoxSettingsViewModel : NotifyBase
    {
        public BoxSettingsViewModel()
        {
        }

        public void RefreshModel()
        {
            DataResult<WorkingInfoEntity> dataRes = LocalDataAccess.GetWorkingInfo();
            if (!dataRes.State)
            {
                MessageBox.Show($"数据库操作异常:{dataRes.Message}", "数据库操作失败提示框", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                var boxStateResult = LocalDataAccess.GetBoxesStates();
                if (!boxStateResult.State)
                {
                    MessageBox.Show($"数据库操作异常: {boxStateResult.Message}", "数据库操作失败提示框", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {

                    if (boxStateResult.Data != null && boxStateResult.Data.Count > 0)
                    {
                        BoxCountList.Clear(); // 先清空,然后插入.
                        foreach (var boxInfo in boxStateResult.Data!)
                        {
                            BoxCountMaxModel model = new BoxCountMaxModel();
                            model.BoxNumber = int.Parse(boxInfo.BoxNumber!);
                            model.CountMax = int.Parse(boxInfo.CountMax!);
                            BoxCountList.Add(model);
                        }
                    }
                }
            }
        }

        private ObservableCollection<BoxCountMaxModel> _boxCountList = new ObservableCollection<BoxCountMaxModel>();

        public ObservableCollection<BoxCountMaxModel> BoxCountList
        {
            get { return _boxCountList; }
            set { SetProperty(ref _boxCountList, value); }
        }


    }
}
